﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Xml;
using PlugNT.Common;
using PlugNT.Custom;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Global
{
    public partial class SetUsers : AdminPage
    {
        public int otherCode = (int)UsersPassType.other;
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                InitConfigs();
            }
        }


        #region 初始化配置信息
        public void InitConfigs()
        {
            txtUserstablename.Text = WebConfig.UsersTableName;
            txtUsersidname.Text = WebConfig.UsersIdName;
            txtUsersusername.Text = WebConfig.UsersUserName;
            txtUserspassname.Text = WebConfig.UsersPassName;
            ddlUsersencryptway.Items.Add(new ListItem("标准MD5加密",((int)UsersPassType.standard).ToString()));
            ddlUsersencryptway.Items.Add(new ListItem("自定义加密", ((int)UsersPassType.custom).ToString()));
            ddlUsersencryptway.Items.Add(new ListItem("其他方式加密", ((int)UsersPassType.other).ToString()));
            ddlUsersencryptway.SelectedValue = WebConfig.UsersEncryptWay;
            txtUsersencryptinterface.Text = WebConfig.UsersEncryptInterface;
            txtUsersselectfields.Text = WebConfig.UsersSelectFields;
            txtUserslockeds.Text = WebConfig.UsersLockeds;

            txtUsersadminhtml.Text = PlugNT.Cms.BLL.Sys.Info.usersadminhtml;

        }
        #endregion



        protected void btnTableUpdate_Click(object sender, EventArgs e)
        {

            NameValue tablename = new NameValue("/configs/users/tablename", txtUserstablename.Text.Trim());
            NameValue idname = new NameValue("/configs/users/idname", txtUsersidname.Text.Trim());
            NameValue username = new NameValue("/configs/users/username", txtUsersusername.Text.Trim());
            NameValue passname = new NameValue("/configs/users/passname", txtUserspassname.Text.Trim());
            NameValue encryptway = new NameValue("/configs/users/encryptway", ddlUsersencryptway.SelectedValue.Trim());
            NameValue encryptinterface = new NameValue("/configs/users/encryptinterface", txtUsersencryptinterface.Text.Trim());
            NameValue selectfields = new NameValue("/configs/users/selectfields", txtUsersselectfields.Text.Trim());
            NameValue lockeds = new NameValue("/configs/users/lockeds", txtUserslockeds.Text.Trim());

            string error = WebSeting.Update(tablename, idname, username, passname, encryptway, encryptinterface, selectfields, lockeds);
            if (error == "")
            {
                Response.Redirect("../Message.aspx?message=用户表配置修改成功！&z=yes");
            }
            else
            {
                Response.Redirect("../Message.aspx?message=用户表配置修改失败：" + error + "&z=no");
            }
        }

        protected void btnHtmlUpdate_Click(object sender, EventArgs e)
        {
            PlugNT.Cms.BLL.Sys.Info.usersadminhtml = txtUsersadminhtml.Text.Trim();
            if (PlugNT.Cms.BLL.Sys.UpdateUsersadminhtml())
            {
                Response.Redirect("../Message.aspx?message=修改后台操作html代码成功！&z=yes");
            }
            else
            {
                Response.Redirect("../Message.aspx?message=修改后台操作html代码失败！&z=no");
            }
        }
    }
}